﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace HalconDotNet
{
	// Token: 0x02000088 RID: 136
	[EditorBrowsable(EditorBrowsableState.Never)]
	public class HDevThread : IDisposable
	{
		// Token: 0x06001DE3 RID: 7651 RVA: 0x000B5037 File Offset: 0x000B3237
		internal IntPtr InternalCallback(IntPtr dummy)
		{
			if (this.mExternalDelegate != null)
			{
				this.mExternalDelegate(this);
			}
			return IntPtr.Zero;
		}

		// Token: 0x06001DE4 RID: 7652 RVA: 0x000B5055 File Offset: 0x000B3255
		internal static void HCkHLib(int err)
		{
			if (HalconAPI.IsFailure(err))
			{
				throw new HalconException(err, "");
			}
		}

		// Token: 0x06001DE5 RID: 7653 RVA: 0x000B506C File Offset: 0x000B326C
		public HDevThread(HDevThreadContext context, HDevThread.ProcCallback proc, int numIn, int numOut)
		{
			HDevThread.HCkHLib(HalconAPI.HXCreateHThread(context.Handle, out this.mThreadHandle));
			GC.KeepAlive(context);
			this.mParamsInput = new HDevInputParam[numIn];
			this.mParamsOutput = new HDevOutputParam[numOut];
			this.mInternalDelegate = new HalconAPI.HDevThreadInternalCallback(this.InternalCallback);
			this.mExternalDelegate = proc;
			this.mSelfRef = GCHandle.Alloc(this);
		}

		// Token: 0x06001DE6 RID: 7654 RVA: 0x000B50D9 File Offset: 0x000B32D9
		public bool IsDirectCall()
		{
			return this.mDirectCall;
		}

		// Token: 0x06001DE7 RID: 7655 RVA: 0x000B50E4 File Offset: 0x000B32E4
		public void Start()
		{
			this.mDirectCall = false;
			IntPtr intPtr;
			HDevThread.HCkHLib(HalconAPI.HXStartHThreadDotNet(this.mThreadHandle, this.mInternalDelegate, IntPtr.Zero, out intPtr));
		}

		// Token: 0x06001DE8 RID: 7656 RVA: 0x000B5118 File Offset: 0x000B3318
		public void ParStart(out HTuple parHandle)
		{
			this.mDirectCall = false;
			IntPtr ip;
			HDevThread.HCkHLib(HalconAPI.HXStartHThreadDotNet(this.mThreadHandle, this.mInternalDelegate, IntPtr.Zero, out ip));
			parHandle = new HTuple(ip);
		}

		// Token: 0x06001DE9 RID: 7657 RVA: 0x000B5151 File Offset: 0x000B3351
		public void CallProc()
		{
			this.mDirectCall = true;
			HDevThread.HCkHLib(HalconAPI.HXPrepareDirectCall(this.mThreadHandle));
			if (this.mExternalDelegate != null)
			{
				this.mExternalDelegate(this);
			}
		}

		// Token: 0x06001DEA RID: 7658 RVA: 0x000B5180 File Offset: 0x000B3380
		public static void ParJoin(HTuple par_handle)
		{
			for (int i = 0; i < par_handle.Length; i++)
			{
				HDevThread.HCkHLib(HalconAPI.HXJoinHThread(par_handle[i].IP));
			}
		}

		// Token: 0x06001DEB RID: 7659 RVA: 0x000B51B4 File Offset: 0x000B33B4
		public void Exit()
		{
			HDevThread.HCkHLib(HalconAPI.HXExitHThread(this.mThreadHandle));
			this.mSelfRef.Free();
		}

		// Token: 0x06001DEC RID: 7660 RVA: 0x000B51D4 File Offset: 0x000B33D4
		public void Dispose()
		{
			for (int i = 0; i < this.mParamsInput.Length; i++)
			{
				this.mParamsInput[i].Dispose();
			}
			if (this.mThreadHandle != IntPtr.Zero)
			{
				this.mThreadHandle = IntPtr.Zero;
			}
		}

		// Token: 0x06001DED RID: 7661 RVA: 0x000B521E File Offset: 0x000B341E
		public void SetInputIconicParamObject(int parIndex, HObject obj)
		{
			this.mParamsInput[parIndex] = new HDevInputParamObject(obj);
		}

		// Token: 0x06001DEE RID: 7662 RVA: 0x000B522E File Offset: 0x000B342E
		public void SetInputIconicParamVector(int parIndex, HObjectVector vector)
		{
			this.mParamsInput[parIndex] = new HDevInputParamVector(vector);
		}

		// Token: 0x06001DEF RID: 7663 RVA: 0x000B523E File Offset: 0x000B343E
		public void SetInputCtrlParamTuple(int parIndex, HTuple tuple)
		{
			this.mParamsInput[parIndex] = new HDevInputParamTuple(tuple);
		}

		// Token: 0x06001DF0 RID: 7664 RVA: 0x000B522E File Offset: 0x000B342E
		public void SetInputCtrlParamVector(int parIndex, HTupleVector vector)
		{
			this.mParamsInput[parIndex] = new HDevInputParamVector(vector);
		}

		// Token: 0x06001DF1 RID: 7665 RVA: 0x000B524E File Offset: 0x000B344E
		public HObject GetInputIconicParamObject(int parIndex)
		{
			return this.mParamsInput[parIndex].GetIconicParamObject();
		}

		// Token: 0x06001DF2 RID: 7666 RVA: 0x000B525D File Offset: 0x000B345D
		public HObjectVector GetInputIconicParamVector(int parIndex)
		{
			return this.mParamsInput[parIndex].GetIconicParamVector();
		}

		// Token: 0x06001DF3 RID: 7667 RVA: 0x000B526C File Offset: 0x000B346C
		public HTuple GetInputCtrlParamTuple(int parIndex)
		{
			return this.mParamsInput[parIndex].GetCtrlParamTuple();
		}

		// Token: 0x06001DF4 RID: 7668 RVA: 0x000B527B File Offset: 0x000B347B
		public HTupleVector GetInputCtrlParamVector(int parIndex)
		{
			return this.mParamsInput[parIndex].GetCtrlParamVector();
		}

		// Token: 0x06001DF5 RID: 7669 RVA: 0x000B528A File Offset: 0x000B348A
		public void BindOutputIconicParamObject(int parIndex, bool global, HObject obj)
		{
			this.mParamsOutput[parIndex] = new HDevOutputParamObject(obj, global);
		}

		// Token: 0x06001DF6 RID: 7670 RVA: 0x000B529B File Offset: 0x000B349B
		public void BindOutputIconicParamVector(int parIndex, bool global, HObjectVector vector, HTuple index)
		{
			this.mParamsOutput[parIndex] = new HDevOutputParamVector(vector, index, global);
		}

		// Token: 0x06001DF7 RID: 7671 RVA: 0x000B52AE File Offset: 0x000B34AE
		public void BindOutputIconicParamVector(int parIndex, bool global, HObjectVector vector)
		{
			this.BindOutputIconicParamVector(parIndex, global, vector, new HTuple());
		}

		// Token: 0x06001DF8 RID: 7672 RVA: 0x000B52BE File Offset: 0x000B34BE
		public void BindOutputCtrlParamTuple(int parIndex, bool global, HTuple tuple)
		{
			this.mParamsOutput[parIndex] = new HDevOutputParamTuple(tuple, global);
		}

		// Token: 0x06001DF9 RID: 7673 RVA: 0x000B529B File Offset: 0x000B349B
		public void BindOutputCtrlParamVector(int parIndex, bool global, HTupleVector vector, HTuple index)
		{
			this.mParamsOutput[parIndex] = new HDevOutputParamVector(vector, index, global);
		}

		// Token: 0x06001DFA RID: 7674 RVA: 0x000B52CF File Offset: 0x000B34CF
		public void BindOutputCtrlParamVector(int parIndex, bool global, HTupleVector vector)
		{
			this.BindOutputCtrlParamVector(parIndex, global, vector, new HTuple());
		}

		// Token: 0x06001DFB RID: 7675 RVA: 0x000B52E0 File Offset: 0x000B34E0
		public void StoreOutputIconicParamObject(int parIndex, HObject obj)
		{
			HDevOutputParam hdevOutputParam = this.mParamsOutput[parIndex];
			using (HDevParamGuard hdevParamGuard = new HDevParamGuard(this.mThreadHandle, hdevOutputParam.IsGlobal()))
			{
				if (hdevParamGuard.IsAvailable())
				{
					hdevOutputParam.StoreIconicParamObject(obj);
				}
			}
		}

		// Token: 0x06001DFC RID: 7676 RVA: 0x000B5334 File Offset: 0x000B3534
		public void StoreOutputIconicParamVector(int parIndex, HObjectVector vector)
		{
			HDevOutputParam hdevOutputParam = this.mParamsOutput[parIndex];
			using (HDevParamGuard hdevParamGuard = new HDevParamGuard(this.mThreadHandle, hdevOutputParam.IsGlobal()))
			{
				if (hdevParamGuard.IsAvailable())
				{
					hdevOutputParam.StoreIconicParamVector(vector);
				}
			}
		}

		// Token: 0x06001DFD RID: 7677 RVA: 0x000B5388 File Offset: 0x000B3588
		public void StoreOutputCtrlParamTuple(int parIndex, HTuple tuple)
		{
			HDevOutputParam hdevOutputParam = this.mParamsOutput[parIndex];
			using (HDevParamGuard hdevParamGuard = new HDevParamGuard(this.mThreadHandle, hdevOutputParam.IsGlobal()))
			{
				if (hdevParamGuard.IsAvailable())
				{
					hdevOutputParam.StoreCtrlParamTuple(tuple);
				}
			}
		}

		// Token: 0x06001DFE RID: 7678 RVA: 0x000B53DC File Offset: 0x000B35DC
		public void StoreOutputCtrlParamVector(int parIndex, HTupleVector vector)
		{
			HDevOutputParam hdevOutputParam = this.mParamsOutput[parIndex];
			using (HDevParamGuard hdevParamGuard = new HDevParamGuard(this.mThreadHandle, hdevOutputParam.IsGlobal()))
			{
				if (hdevParamGuard.IsAvailable())
				{
					hdevOutputParam.StoreCtrlParamVector(vector);
				}
			}
		}

		// Token: 0x04001153 RID: 4435
		private IntPtr mThreadHandle;

		// Token: 0x04001154 RID: 4436
		private bool mDirectCall;

		// Token: 0x04001155 RID: 4437
		private HDevInputParam[] mParamsInput;

		// Token: 0x04001156 RID: 4438
		private HDevOutputParam[] mParamsOutput;

		// Token: 0x04001157 RID: 4439
		private GCHandle mSelfRef;

		// Token: 0x04001158 RID: 4440
		private HalconAPI.HDevThreadInternalCallback mInternalDelegate;

		// Token: 0x04001159 RID: 4441
		private HDevThread.ProcCallback mExternalDelegate;

		// Token: 0x020000B8 RID: 184
		// (Invoke) Token: 0x06002073 RID: 8307
		public delegate void ProcCallback(HDevThread devThread);
	}
}
